package com.ning.farm_income_back.controller;

import com.github.pagehelper.PageInfo;
import com.ning.farm_income_back.domain.Agriculturalassets;
import com.ning.farm_income_back.domain.Land;
import com.ning.farm_income_back.domain.Users;
import com.ning.farm_income_back.dto.AgriculturalassetsDto;
import com.ning.farm_income_back.service.AssetsService;
import com.ning.farm_income_back.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/assets")
public class AssetsController {
    @Autowired
    AssetsService assetsService;

    //分页带条件查询
    @PostMapping("/page")//处理 HTTP POST 请求（新增操作）
    public ResultVo<PageInfo> page(@RequestBody AgriculturalassetsDto assets, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "3") Integer pageSize ) {
        if(pageNum == null || pageNum < 1) pageNum = 1;

        //获取页面数据 总条数 总页数
        PageInfo pageInfo = assetsService.getPage(assets,pageNum,pageSize);

        return ResultVo.success("页面数据查询成功",pageInfo);
    }

    //新增
    @PostMapping("/saveAssets")
    public ResultVo saveAssets(@RequestBody AgriculturalassetsDto assetsDto) {
        assetsService.saveAssetsInfo(assetsDto);
        return ResultVo.success("新增成功！");
    }

    //修改
    @PutMapping("/updateAssets")
    public ResultVo updateLand(@RequestBody AgriculturalassetsDto assetsDto) {
        assetsService.updateAssetsInfo(assetsDto);
        return ResultVo.success("修改成功！");
    }

    //删除
    @DeleteMapping("/deleteAssets/{id}")
    public ResultVo deleteAssets(@PathVariable Integer id) {
        assetsService.deleteAssetsInfo(id);
        return ResultVo.success("删除成功！");
    }
}
